#include "forgetpassword2.h"
#include "ui_forgetpassword2.h"
#include "forgetpassword3.h"
#include<QtDebug>
#include<QMessageBox>
#include<QSqlQuery>
#include"titlebarfix.h"
forgetpassword2::forgetpassword2(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::forgetpassword2)
{
    //关闭窗口，即销毁窗体
    this->setAttribute(Qt::WA_DeleteOnClose, true);

    ui->setupUi(this);
    //设置lable的颜色 选中状态
    QPalette pa;
    pa.setColor(QPalette::WindowText,Qt::white);
    ui->label_2->setPalette(pa);
    //设置窗口图标
    this->setWindowIcon(QIcon(":/images/软件图标.png"));
}

forgetpassword2::~forgetpassword2()
{
    delete ui;
}

void forgetpassword2::on_pushButton_next_clicked()
{

    //密码校验
    QString password1=ui->lineEdit->text();
    QString password2=ui->lineEdit_2->text();

    if(password1==password2&&password1!=nullptr){
        QSqlQuery query;
        QString sql_update=QString("update user set password='%1' where email='%2'").arg(password1).arg(this->email);
        qDebug()<<"sql_update:"<<sql_update;
        query.exec(sql_update);


        emit sendsignal();
        this->close();


        forgetpassword3*fgp3=new forgetpassword3;
        titlebarFix *tBar=new titlebarFix;
        connect(fgp3,SIGNAL(sendsignal()),tBar,SLOT(close()));
        tBar->setAttribute(Qt::WA_DeleteOnClose, true);
        tBar->setMainWidget(fgp3);
        tBar->setTitleBarText(QStringLiteral("重置成功"));
        tBar->show();
//        fgp3->show();

    }
    else {
        QMessageBox::warning(this,QStringLiteral("密码重置失败"),QStringLiteral("请重新输入密码"));
    }



}

void forgetpassword2::getEmail(QString email)
{
    qDebug()<<"email:"<<email;
    this->email=email;
}
